﻿namespace CountTools
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class ProgressBarExport : Form
    {
        public bool bAbort;
        public Button buttonAbort;
        //private IContainer components;
        public Label label_progress;
        public ProgressBar progressBarEx;
        private Stopwatch textSW = new Stopwatch();

        public ProgressBarExport()
        {
            this.InitializeComponent();
            this.textSW.Start();
        }

        private void buttonAbort_Click(object sender, EventArgs e)
        {
            this.bAbort = true;
            this.Close();
        }

        protected override void Dispose(bool disposing)
        {
            //if (disposing && (this.components != null))
            //{
            //    this.components.Dispose();
            //}
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.progressBarEx = new System.Windows.Forms.ProgressBar();
            this.buttonAbort = new System.Windows.Forms.Button();
            this.label_progress = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // progressBarEx
            // 
            this.progressBarEx.Location = new System.Drawing.Point(12, 12);
            this.progressBarEx.Name = "progressBarEx";
            this.progressBarEx.Size = new System.Drawing.Size(300, 23);
            this.progressBarEx.Step = 1;
            this.progressBarEx.TabIndex = 0;
            // 
            // buttonAbort
            // 
            this.buttonAbort.Location = new System.Drawing.Point(237, 61);
            this.buttonAbort.Name = "buttonAbort";
            this.buttonAbort.Size = new System.Drawing.Size(75, 23);
            this.buttonAbort.TabIndex = 1;
            this.buttonAbort.Text = "取消";
            this.buttonAbort.UseVisualStyleBackColor = true;
            this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
            // 
            // label_progress
            // 
            this.label_progress.AutoSize = true;
            this.label_progress.Location = new System.Drawing.Point(13, 42);
            this.label_progress.Name = "label_progress";
            this.label_progress.Size = new System.Drawing.Size(67, 15);
            this.label_progress.TabIndex = 2;
            this.label_progress.Text = "进程说明";
            // 
            // ProgressBarExport
            // 
            this.ClientSize = new System.Drawing.Size(319, 96);
            this.ControlBox = false;
            this.Controls.Add(this.label_progress);
            this.Controls.Add(this.buttonAbort);
            this.Controls.Add(this.progressBarEx);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "ProgressBarExport";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "自动清单编码 ...";
            this.TopMost = true;
            this.Shown += new System.EventHandler(this.ProgressBarExport_Shown);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public void PerformStep()
        {
            this.progressBarEx.PerformStep();
            System.Windows.Forms.Application.DoEvents();
        }

        private void ProgressBarExport_Shown(object sender, EventArgs e)
        {
        }

        public bool SetTextInfo(string text, long intervalMs = 0L)
        {
            if (this.textSW.ElapsedMilliseconds >= intervalMs)
            {
                this.textSW.Restart();
                this.label_progress.Text = text;
                return true;
            }
            return false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

